<table id="group_datagrid_${action_id}" ></table>
<div id="auth_group_datagrid_tb_${action_id}" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		<a href="javascript:;;" onclick="auth_group_add_${action_id}();" class="easyui-linkbutton" iconCls="icon-add" plain="true" >${action.getProperty('net.esj.background.message','bg.datagrid.add')}</a>
		<a href="javascript:;;" onclick="auth_group_delete_${action_id}();" class="easyui-linkbutton" iconCls="icon-remove" plain="true">${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>
		&nbsp;&nbsp;&nbsp;&nbsp;
	</div>
</div>
<script type="text/javascript">
var auth_group_current_model_${action_id} = '${id?default('')}';
$(function(){

	$('#group_datagrid_${action_id}').datagrid({
		iconCls:'icon-save',
		width:'auto',
		height:'auto',
		nowrap: false,
		fit:true,
		singleSelect:true,
		fitColumns:true,
		striped: true,
		url:'${request.contextPath}${namespace?default('')}/mp/auth/group-datagrid.json?key=${key?default('')}',
		queryParams:{'_searcher_eq_model#id':'${id?default('')}'},
		sortName: 'name',
		sortOrder: 'desc',
		remoteSort: true,
		idField:'id',
		onBeforeLoad:function(){$('#group_datagrid_${action_id}').datagrid('unselectAll');},
		columns:[[
					//{field:'ck',checkbox:true},
					{field:'name',title:'${action.getDatagridTitle('name')}',width:40,align:'center',sortable:true},
					{field:'descriptions',title:'${action.getDatagridTitle('descriptions')}',width:80,align:'center',sortable:true},
					{field:'caozuo',title:'${action.getProperty('net.esj.background.message','bg.datagrid.action')}',width:20,align:'center',sortable:false,formatter:function(val, rec){
						return '<a href="javascript:;;" onclick="group_edit_${action_id}(\''+rec.id+'\')" >${action.getProperty('net.esj.background.message','bg.datagrid.modify')}</a>';
					}}
				]],
		pagination:true,
		rownumbers:true,
		toolbar:'#auth_group_datagrid_tb_${action_id}'
	});

});

function auth_group_add_${action_id}(){
	$('<div/>').dialog({
		href:'${request.contextPath}${namespace?default('')}/mp/auth/group-form.htm?key=${key?default('')}&model.id='+auth_group_current_model_${action_id},
		width:500,   
		height:400,   
		title: '${action.getText('form.add.title')}',
		modal:true,
		maximizable:false,
		collapsible:false,
		minimizable:false,
		resizable:false,
		buttons:[{iconCls : 'icon-ok',
					text:'${action.getProperty('net.esj.background.message','bg.datagrid.save')}',
					handler:function(){
						var d = $(this).closest('.window-body');
						d.find('#group_addForm').form('submit', {
							url : '${request.contextPath}${namespace?default('')}/mp/auth/group-add.json?key=${key?default('')}',
							onSubmit: function(){
								var nodes = d.find('#group_addForm').find('#funcTree').tree('getChecked');
								var ids = [] ;
								for(var i=0;i<nodes.length;i++){
									ids.push(nodes[i].id);
								}
								d.find('#group_addForm').find('[name="entity.funcsStr"]').val(ids.join(';'));
								return $(this).form('validate');
	        				},
							success : function(json) {
								eval("json="+json);
								$.messager.alert(json.title,json.msg,json.level);
								d.dialog('destroy');
								$("#group_datagrid_${action_id}").datagrid('reload');
							}
						});
					}}],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			var d = $(this).closest('.window-body');
			var form = d.find('#group_addForm');
			form.find('#funcTree').tree({
				url:'${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json?key=${key?default('')}&model.id='+auth_group_current_model_${action_id}
			});
		}
	});
}

function group_edit_${action_id}(id) {
	$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/mp/auth/group-form.htm?key=${key?default('')}&model.id='+auth_group_current_model_${action_id},
		width:500,   
		height:400,   
		modal : true,
		title : '${action.getText('form.edit.title')}',
		buttons : [ {
			text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				d.find('#group_addForm').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/mp/auth/group-update.json?key=${key?default('')}',
					onSubmit: function(){
						var nodes = d.find('#group_addForm').find('#funcTree').tree('getChecked');
						var ids = [] ;
						for(var i=0;i<nodes.length;i++){
							ids.push(nodes[i].id);
						}
						d.find('#group_addForm').find('[name="entity.funcsStr"]').val(ids.join(';'));
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						d.dialog('destroy');
						$("#group_datagrid_${action_id}").datagrid('reload');
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			var d = $(this).closest('.window-body');
			var form = d.find('#group_addForm');
			form.find('#funcTree').tree({
				url:'${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json?key=${key?default('')}&model.id='+auth_group_current_model_${action_id},
				onLoadSuccess:function(){
					$.get('${request.contextPath}${namespace?default('')}/mp/auth/group-load.json?key=${key?default('')}&id='+id+'&n='+Math.random(),{},function(data){
						eval("data="+data);
						form.form('load',data);
						for(var i = 0;i<data["entity.funcs"].length;i++){
							var node = form.find('#funcTree').tree('find',data["entity.funcs"][i]);
							if(node){
								form.find('#funcTree').tree('check',node.target);
							}
						}
					});
				}
			});
		}
	});
}

function auth_group_delete_${action_id}() {
	var ids = [];
	var rows = $('#group_datagrid_${action_id}').datagrid('getSelections');
	if(rows.length==0){
		$.messager.alert('${action.getText('system.message.alert')}', '${action.getText('system.delete.select')}', 'warning');
	}
	
	for(var i=0;i<rows.length;i++){
		ids.push(rows[i].id);
	}
	if(ids.length>0){
		$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getProperty('net.esj.background.message','bg.datagrid.delete.ask')}', function(b) {
			if (b) {
				$.ajax({
					url : '${request.contextPath}${namespace?default('')}/mp/auth/group-delete.json?key=${key?default('')}',
					data:{deletes : ids.join(';')},
					dataType : 'JSON',
					success : function(json) {
						$.messager.alert(json.title,json.msg,json.level);
						$("#group_datagrid_${action_id}").datagrid('reload');
						$('#group_datagrid_${action_id}').datagrid('clearSelections');
					}
				});
			}
		});
	}
}

</script>	